package com.dmz.etc.task.utils.ftp;

import cn.hutool.extra.ftp.Ftp;
import com.dmz.common.utils.secure.GMUtil;
import com.dmz.etc.task.config.EnvConfig;
import lombok.Data;
import lombok.extern.slf4j.Slf4j;

/**
 * @author lee
 */
@Data
@Slf4j
public class FtpClient {
    private String host;

    private int port;

    private String username;

    private String password;

    public Ftp dmzFtp() {

        String key = EnvConfig.getProperty("sm4.key");
        String iv = EnvConfig.getProperty("sm4.iv");

        this.host = EnvConfig.getProperty("dmz.ftp.host");
        this.port = Integer.valueOf(EnvConfig.getProperty("dmz.ftp.port"));
        String usernameEb = EnvConfig.getProperty("dmz.ftp.username");
        String passwordEb = EnvConfig.getProperty("dmz.ftp.password");
        this.username = GMUtil.db(key, iv, usernameEb);
        this.password = GMUtil.db(key, iv, passwordEb);
        log.info("dmz FTP:{}", host);
        log.info("dmz FTP username:{}", username);
        log.info("dmz FTP password:{}", password);
        return new Ftp(host, port, username, password);
    }

    public Ftp cspFtp() {

        String key = EnvConfig.getProperty("sm4.key");
        String iv = EnvConfig.getProperty("sm4.iv");
        this.host = EnvConfig.getProperty("csp.ftp.host");
        this.port = Integer.valueOf(EnvConfig.getProperty("csp.ftp.port"));
        String usernameEb = EnvConfig.getProperty("csp.ftp.username");
        String passwordEb = EnvConfig.getProperty("csp.ftp.password");
        this.username = GMUtil.db(key, iv, usernameEb);
        this.password = GMUtil.db(key, iv, passwordEb);
        log.info("csp FTP:{}", host);
        log.info("csp FTP username:{}", username);
        log.info("csp FTP password:{}", password);
        return new Ftp(host, port, username, password);
    }
}
